<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :show="show" @click-show="show = !show" :fixed="true" :back="true" color="#fff" :title="title"></uni-navbar></view>

		<!-- <view class="filter-box" v-if="show">
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="标题" labelAlign="left" label-width="190"><u-input v-model="perform.title" type="text" placeholder="请输入标题" /></u-form-item>
					<u-form-item class="form-item" label="届次" labelAlign="left" label-width="190">
						<u-input v-model="jieci" type="select" :select-open="jcShow" placeholder="请选择届次" @click="jcShow = true" />
						<u-select v-model="jcShow" mode="mutil-column-auto" :list="jcList" @confirm="jcConfirm"></u-select>
					</u-form-item>
				</u-form>
			</view>
			<view class="fiexd-btm">
				<view class="flex-box">
					<u-button class="form-btn" type="default" @click="resert">清除</u-button>
					<u-button class="form-btn" type="error" @click="filter">确定</u-button>
				</view>
			</view>
		</view>
		
		<view class="search-view">
			<u-search class="search-input" v-model="listQuery.title" :show-action="false" @search="search" @custom="show = !show"></u-search>
			<view class="" style="display: flex;align-items: center;">
				<image style="width: 26upx;height: 30upx;" src="../../../static/sx.png" mode=""></image>
				<text style="font-size: 14px;color: #666666;padding-left: 10upx;">筛选</text>
			</view>
		</view> -->
		
		
		<!-- <u-tabs class="uTabs" :list="tabsList" :is-scroll="false" v-model="tabsCurrent" @change="tabsChange"></u-tabs> -->
		
		<view class="tabsList2">
			<view class="tabsList2Item" @tap="sxconfirm(index)" :class="titleCoust == index ? 'inactive' : 'unactive'" v-for="(item,index) of xcjzTypeList" :key="index">
				{{ item.name }}
			</view> 
		</view>
		
		<u-gap height="20" bgColor="#F6F7FB"></u-gap>
		
		
		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-info_01" v-for="(item, index) of ysList" :key="index" @click="navTo(item)">
				<view class="info-title">{{ item.title }}</view>
				<view class="info-btm">
					<view class="btm-left clamp">
						<!-- <text class="left-name" >{{ item.createByName }}</text> -->
						<text class="left-time">{{ item.submitTime }}</text>
						<text class="left-time" style="padding-left: 20rpx;">{{ item.submitName }}</text>
					</view>
					<view class="btm-right">
						<!-- <view class="right-type" :style="'color:' + colorMap[item.nodeStatus]">{{ statusMap[item.nodeStatus] }}</view> -->
					</view>
				</view>
				
			</view>
			<view class="noMessage" v-if="isNoMessage">
				<view class="noMessageImg">
					<image src="@/static/result-img/no-data.png" mode=""></image>
				</view>
				<!-- <view class="noMessageText">
					暂无内容
				</view> -->
			</view> 
			
			<u-loadmore v-if="isno" :status="loading" />
		</view>
		<image src="/static/img/icon_tianbao.png" mode="widthFix" class="tianbao" @click="editTo" v-if="$sysBtns(flag + '_add')"></image>
		<u-back-top :scroll-top="scrollTop" top="200" style="right: 40rpx; bottom: 50rpx"></u-back-top>

		<view v-if="false && flag"></view>
		
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			isNoMessage:false,
			isno:false,
			titleCoust:0,
			xcjzTypeList:[],
			tabsCurrent: 0,
			loading: 'nomore',
			ysList:[],
			listQuery:{
				title:'',
				currentUserId:'',
				clientCode:'370782',
				dbzjDeptId:'',
				dataRange:'',
				isSource:'',
				isNode:'',
				isReview:'',
				flagNew:'',
				pageSize:'10',
				pageNum:'1'
			},
			repUserId:''
		};
	},
	onLoad(option) {
		// this.loadLogin()
		// if(option.id){
		// 	this.id = option.id
		// 	this.getList()
		// }
		
		if(option.repUserId){
		 this.repUserId = option.repUserId
		 uni.setStorageSync('repUserId',option.repUserId)
		}
		
		this.getList1()
	},
	onPullDownRefresh() {
		this.getList1()
	},
	onReachBottom() {
		if(!this.isno){
			this.getAlllist()
		}
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		sxconfirm(e){
			let that = this
			this.titleCoust = e
			this.id = that.xcjzTypeList[e].dbzjDeptId
			this.listQuery.pageNum = 1
			this.isno = false
			this.getList()
			// uni.navigateTo({
			// 	url:'../tbwtInfo/tbwtInfo?id=' + that.xcjzTypeList[e].dbzjDeptId
			// })
		},
		getZJ(e){
			uni.navigateTo({
				url:'/pagesB/msys/dbzjInfo/dbzjInfo?id=' + e.id
			})
		},
		getList1(){
			let that = this
			let url = '/minqingzhitong/msManageDept/list';
			this.$request(url, {
				type: "1",
				pageNum:'1',
				pageSize:'999'
			} , {
				load: true
			}).then((res) => {
				if(res.code == 200){
					let a = {
						name:'全部',
						dbzjDeptId:''
					}
					res.data.records.unshift(a)
					that.xcjzTypeList = res.data.records
					
					this.id = that.xcjzTypeList[0].dbzjDeptId
					this.getList()
					that.$forceUpdate()
				}
				
			});
		},
		getList(e = 0){
			let that = this
			let url = '/msIssueInfo/list';
			let a = JSON.parse(JSON.stringify(that.listQuery))
			a.dbzjDeptId = that.id
			if(e == 0){
				a.isNode = '5'
				a.isReview = '1'
			}
			
			
			
			this.$request(url, a , {
				load: true
			}).then((res) => {
				if(res.code == 200){
					if(res.data && res.data.records.length !== 0){
						that.ysList = res.data.records
					}else{
						that.ysList = []
						that.isNoMessage = true
					}
				}
				
			});
		},
		getAlllist(e = 0){
			let that = this
			let url = '/msIssueInfo/list';
			let a = JSON.parse(JSON.stringify(that.listQuery))
			a.dbzjDeptId = that.id
			if(e == 0){
				a.isNode = '5'
				a.isReview = '1'
			}
			
			a.pageNum++
			
			this.$request(url, a , {
				load: true
			}).then((res) => {
				if(res.code == 200){
					if(res.data.records.length !== 0){
						that.listQuery.pageNum++
						that.ysList.push(...res.data.records)
					}else{
						that.isno = true
						
					}
				}
				
			});
		},
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.roleCodes = this.userInfo.roleCodes.join(',');

				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				// this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.perform.nodeStatus == '-1') {
				this.perform.nodeStatus = '';
			}
			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				currentUserId: this.userId,
				clientCode: this.clientCode,
				roleCodes: this.roleCodes,
				perform: this.perform
			};
			this.$request('/perform/myList', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.dutiesList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.dutiesList = this.dutiesList.concat(res.data.records);
				this.loaded = true;
				if (this.dutiesList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		loadDict(type) {
			this.$request('/system/sys-dict/dictList', {
				clientCode: this.clientCode,
				sysDict: {
					dictType: type
				}
			}).then((res) => {
				this.tabsList.push({
					name: '所有',
					value: '-1'
				});
				res.data.forEach((item) => {
					this.tabsList.push({
						name: item.dictName,
						value: item.dictValue
					});
				});
			});
		},
		tabsChange(index) {
			this.tabsCurrent = index;
			this.type(this.tabsList[index].value);
		},
		jcConfirm(e) {
			this.jieci = e[0].label + e[1].label;
			this.perform.jieId = e[0].value;
			this.perform.ciId = e[1].value;
		},
		filter() {
			this.show = false;
			this.loadData('refresh');
		},
		resert() {
			this.show = false;
			this.perform.title = '';
			this.jieci = '';
			this.perform.jieId = '';
			this.perform.ciId = '';
			this.loadData('refresh');
		},
		search(e) {
			this.perform.title = e;
			this.loadData('refresh');
		},
		type(e) {
			this.nodeStatus = e;
			this.perform.nodeStatus = e.toString();
			this.loadData('refresh');
		},
		jieciData() {
			let data = {
				clientCode: this.clientCode,
				jieCi: {
					pid: ''
				}
			};
			this.$request('/jie-ci/list', data).then((res) => {
				this.jcList = [];
				let jieArr = [];
				let ciArr = [];
				res.data.forEach((item) => {
					data.jieCi.pid = item.id;
					this.$request('/jie-ci/list', data).then((res) => {
						ciArr = [];
						res.data.forEach((key) => {
							ciArr.push({
								value: key.id,
								label: key.name
							});
						});
						this.jcList.push({
							value: item.id,
							label: item.name,
							children: ciArr
						});
					});
				});
			});
		},
		navTo(item) {
			let that = this
			if(this.repUserId){
				uni.navigateTo({
					url:'/pagesB/msys/msys/msysInfo/msysInfo?id=' + item.id + '&repUserId=' + that.repUserId
				})
			}else{
				uni.navigateTo({
					url:'/pagesB/msys/msys/msysInfo/msysInfo?id=' + item.id
				})
			}
			
			
			
			// uni.navigateTo({
			// 	url: '/pagesA/duties/detail?flag=' + this.flag + '&code=' + this.perform.module + '&name=' + this.title + '&id=' + item.id
			// });
		},
		editTo(item) {
			uni.navigateTo({
				url: '/pagesA/duties/add?flag=' + this.flag + '&code=' + this.perform.module + '&name=' + this.title
			});
		}
	}
};
</script>

<style lang="scss">
.uTabs {
	min-height: 88rpx;
}

.list-box {
	padding: 0 30rpx;
	background-color: #fff;
}

.tianbao {
	display: block;
	position: fixed;
	right: 40rpx;
	bottom: 170rpx;
	width: 160rpx;
	height: 160rpx;
}

.filter-box {
	position: fixed;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	z-index: 998;
	background-color: #fff;
}

.form-box {
	.form-item {
		@include mp-flex;
		border-bottom: 20rpx solid #f5f7fa;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}

.bottomBtn{
	position: fixed;
	bottom: 200upx;
	right: 20upx;
	width: 100upx;
	height: 100upx;
	text-align: center;
	background-color: red;
	border-radius: 50%;
	padding: 10upx;
	color: #fff;
	.bottomBtnInfo{
		font-size: 15px;
	}
}

.changeBtnList{
	display: flex;
	align-items: center;
	justify-content: flex-end;
	flex-wrap: wrap;
	margin-top: 20upx;
	.changeBtnListItem{
		padding: 10upx 20upx;
		border: 1upx solid #999999;
		margin: 0 10upx;
	}
}

.tabsList2{
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	margin: 26upx 20upx;
	.tabsList2Item{
		width: 225.34upx;
		text-align: center;
		border-radius: 10upx;
		line-height: 60upx;
		
		padding: 0 14upx;
		margin-left: 12upx;
		margin-bottom: 24upx;
		
		overflow:hidden;
		text-overflow:ellipsis;
		white-space:nowrap;
		font-size: 24upx;
	}
}

.inactive{
	color: #ffffff;
	background-color: #D0021B;
}

.unactive{
	color: #666666;
	background-color: #F9F9F9;
} 

.list-view{
	background-color: #ffffff;
	min-height: 100vh;
}

.noMessage{
	display: flex;
	justify-content: center;
	justify-items: center;
	flex-direction:column;
	margin-top: 80upx;
	.noMessageImg{
		text-align: -webkit-center;
		image{
			width: 676rpx;
			    height: 352rpx;
		}
	}
	
	.noMessageText{
		margin-top: 30upx;
		font-size: 40upx;
		color: #666666;
		text-align: center;
	}
}
</style>
